/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Bean;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import koneksi.koneksi;

/**
 *
 * @author Prasetyawan
 */
public class Login {
    private String idUser;
    private String password;

    public Login (String idUser, String password){
        this.idUser = idUser;
        this.password = password;
    }
    /**
     * @return the idUser
     */
    public String getIdUser() {
        return idUser;
    }

    /**
     * @param idUser the idUser to set
     */
    public void setIdUser(String idUser) {
        this.idUser = idUser;
    }

    /**
     * @return the password
     */
    public String getPassword() {
        return password;
    }

    /**
     * @param password the password to set
     */
    public void setPassword(String password) {
        this.password = password;
    }
    
    public boolean cekLogin (Login log) throws SQLException{
        boolean status = false;
        Connection con = koneksi.open(idUser, idUser, password);
        Statement st = null;
        String idUser = log.getIdUser();
        String password = log.getPassword();
        
        st = con.createStatement();
        
        String sql = "select * from pegawai where username='" + idUser + "' and password='" + password + "'";
        ResultSet rs = null;
        rs = st.executeQuery(sql);
        while (rs.next()){
            if (log.idUser.isEmpty()){
                status = false;
            }else {
                status = true;
            }
        }
            
        return status;
    }
}
